//#include <iostream>
//#include <memory>

#include "sm2_ka.h"
#include "sm3_with_preprocess.h"

/*
void dump_hex(const char *str, unsigned char *hex_data, int len) {
    int i = 0;


    printf("%s", str);
    for (i = 0; i < len; i++) {
        if (i % 16 == 0) printf("\n");
        printf("0x%02x, ", hex_data[i]);
    }
    printf("\n");
}
*/
unsigned char id_A[32] = {
0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38
};
unsigned char id_B[32] = {
0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38
};
unsigned char prikdata_A[32] = {
0x81,0xEB,0x26,0xE9,0x41,0xBB,0x5A,0xF1,0x6D,0xF1,0x16,0x49,0x5F,0x90,0x69,0x52,
0x72,0xAE,0x2C,0xD6,0x3D,0x6C,0x4A,0xE1,0x67,0x84,0x18,0xBE,0x48,0x23,0x00,0x29
};
unsigned char pubx_A[32] = {
0x16,0x0E,0x12,0x89,0x7D,0xF4,0xED,0xB6,0x1D,0xD8,0x12,0xFE,0xB9,0x67,0x48,0xFB,
0xD3,0xCC,0xF4,0xFF,0xE2,0x6A,0xA6,0xF6,0xDB,0x95,0x40,0xAF,0x49,0xC9,0x42,0x32
};
unsigned char puby_A[32] = {
0x4A,0x7D,0xAD,0x08,0xBB,0x9A,0x45,0x95,0x31,0x69,0x4B,0xEB,0x20,0xAA,0x48,0x9D,
0x66,0x49,0x97,0x5E,0x1B,0xFC,0xF8,0xC4,0x74,0x1B,0x78,0xB4,0xB2,0x23,0x00,0x7F
};
unsigned char prikdata_B[32] = {
0x78,0x51,0x29,0x91,0x7D,0x45,0xA9,0xEA,0x54,0x37,0xA5,0x93,0x56,0xB8,0x23,0x38,
0xEA,0xAD,0xDA,0x6C,0xEB,0x19,0x90,0x88,0xF1,0x4A,0xE1,0x0D,0xEF,0xA2,0x29,0xB5
};
unsigned char pubx_B[32] = {
0x6A,0xE8,0x48,0xC5,0x7C,0x53,0xC7,0xB1,0xB5,0xFA,0x99,0xEB,0x22,0x86,0xAF,0x07,
0x8B,0xA6,0x4C,0x64,0x59,0x1B,0x8B,0x56,0x6F,0x73,0x57,0xD5,0x76,0xF1,0x6D,0xFB
};
unsigned char puby_B[32] = {
0xEE,0x48,0x9D,0x77,0x16,0x21,0xA2,0x7B,0x36,0xC5,0xC7,0x99,0x20,0x62,0xE9,0xCD,
0x09,0xA9,0x26,0x43,0x86,0xF3,0xFB,0xEA,0x54,0xDF,0xF6,0x93,0x05,0x62,0x1C,0x4D
};


int test_ex_sm2_main(int argc, const char *argv[])
{

    printf("=======================================\n");
    printf("密钥协商初始化：\n");
    printf("=======================================\n");

    SM2KA ka_a;
    SM2KA ka_b;
	EC_POINT *RA = NULL;
	EC_POINT *RB = NULL;
	EC_POINT *PA = NULL;
	EC_POINT *PB = NULL;

    PA = agreement_init(&ka_a, prikdata_A, pubx_A, puby_A, id_A, 16);
    dump_hex("ZA:",ka_a.Z,16);
    PB = agreement_init(&ka_b, prikdata_B, pubx_B, puby_B, id_B, 16);
    dump_hex("ZB:",ka_b.Z,16);
    printf("=======================================\n");
    printf("发送方A：\n");
    printf("=======================================\n");
    RA = gen_agreementdata(&ka_a);
    if(RA ==NULL)
    {
        return -1;
    }
    printf("=======================================\n");
    printf("发送方B：\n");
    printf("=======================================\n");
    RB = gen_agreementdata_key(&ka_b, RA, PA, ka_a.Z);
    if(RB ==NULL)
    {
        return -1;
    }
    printf("=======================================\n");
    printf("发送方A：\n");
    printf("=======================================\n");
    gen_key(&ka_a, RB, PB, ka_b.Z);

    return 0;
}

